<%--
  Created by IntelliJ IDEA.
  User: qiliping
  Date: 16/3/15
  Time: 下午10:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="paging" uri="paging-taglib" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>管理商品</title>
    <script>
        $(function(){
            $(".sale").click(function(){
                var obj = $(this);
                var confr="";
                var isr = $(this).attr("isr");
                if(isr==0){
                    confr="确认要下架商品?";
                }else{
                    confr="确认要禁售商品吗?";
                }
                if(confirm(confr)){
                    var aid = $(this).attr("aid");
                    var isr = $(this).attr("isr");
                    $.ajax({
                        url:"/product/status",
                        type:"post",
                        data:{id:aid,status:isr},
                        success:function(){location.reload(true)}
                    })
                }

            });
        })
    </script>
    <script language="javascript">
        function del_sure(id) {
            var gnl = confirm("确定要删除?");
            console.log(gnl)
            if (gnl) {
                $.get("${ctx}/product/product_delete?id="+id,function(){location.reload(true)})
            }
        }
    </script>
</head>

<body>
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title">
            商品管理
            <small>商品管理</small>
        </h3>
        <ul class="page-breadcrumb breadcrumb">
            <li>
                <i class="fa fa-home"></i>
                <a href="${ctx}/main">
                    首页
                </a>
                <i class="fa fa-angle-right"></i>
            </li>
            <li>
                <a href="#">
                    商品管理
                </a>
                <i class="fa fa-angle-right"></i>
            </li>
            <li>
                <a href="#">
                    商品管理
                </a>
            </li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB-->
    </div>
</div>
<!-- END PAGE HEADER-->
<!------内容区----->
<div class="main">
    <form action="${ctx}/product/product_list" method="get">
        <div class="row">
            <div class="col-md-12">
                <div class="search">
                    <div class="form-group">
                        <label class="control-label">商品名：</label>
                        <input type="text" name="productName" value="${productName}" class="form-control form-control-inline"/>
                    </div>

                    <div class="form-group">
                        <label class="control-label">申请时间：</label>

                        <div class="date-control small">
                            <div class="input-daterange input-group">
                                <input type="text" class="form-control fromdatetime col-md-3" size="16" value="${stime}"
                                       name="stime">
                                <span class="input-group-addon"> - </span>
                                <input type="text" class="form-control todatetime col-md-3" size="16" value="${etime}"
                                       name="etime">
                            </div>
                        </div>
                        <span class="actions">
                        <input class="btn blue" type="submit" value="搜索"/>
                    </span>
                        <span class="actions">
                        <div class="text-right">
                            <a href="${ctx}/product/add" class="btn blue">添加商品</a>
                        </div>
                    </span>
                    </div>
                </div>

            </div>
        </div>

        <%--<div class="row">
            <div class="col-md-12">
                <div class="text-right">

                    <div class="btn-group status-filter">
                        <label class="btn btn-default active">
                            <a class="toggle checked" href="${ctx}/product">所有</a>
                        </label>
                        <label class="btn btn-default">
                            <a class="toggle" href="${ctx}/product?status=3">预约中</a>
                        </label>
                        <label class="btn btn-default">
                            <a class="toggle" href="${ctx}/product?status=4">募集中</a>
                        </label>

                    </div>
                </div>
            </div>
        </div>--%>

        <div class="row">
            <div class="col-md-12">
                <table class="table table-striped table-hover zqy-table">
                    <thead>
                    <tr>
                        <th>产品主图</th>
                        <th>产品名称</th>
                        <th>总销量</th>
                        <th>价格</th>
                        <th>状态</th>
                        <th>编辑</th>
                        <th>删除</th>
                        <th>添加日期</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach var="item" items="${list}">
                        <tr>

                            <td>
                                <img src="${item.productMainImage}" width="100px" height="100px" />
                                <br />
                            <td>${item.productName}</td>
                            <td>
                                    ${item.viewedTotal}
                            </td>
                            <td>${item.salePrice}</td>
                            <td>
                                <c:choose>
                                    <c:when test="${item.status == 1}">
                                       销售中
                                    </c:when>
                                    <c:when test="${item.status == 0}">
                                        已下架
                                    </c:when>
                                    <c:when test="${item.status == 2}">
                                        禁售中
                                    </c:when>
                                </c:choose>
                            </td>
                            <td>
                                <c:choose>
                                    <c:when test="${item.status==0||item.status==2}">
                                        <a href="javascript:void(0);" class="sale" isr="1" aid="${item.productId}">销售</a>
                                    </c:when>
                                    <c:when test="${item.status==1}">
                                        <a href="javascript:void(0);" class="sale" isr="0" aid="${item.productId}">下架</a>
                                    </c:when>
                                </c:choose>

                                <a href="javascript:void(0);" class="sale" isr="2" aid="${item.productId}">禁售</a>
                            </td>
                            <td>
                                <a class="btn btn-xs js-deleteClassify"   onclick="javascript:del_sure('${item.productId}')">删除</a>
                            </td>
                            <td> <fmt:formatDate value="${item.createOn}" pattern="yyyy-MM-dd"></fmt:formatDate> </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <div class="text-center">
                    <ul class="pagination">
                        <paging:paging pageIndex="${pageIndex}" totalPage="${totalPage}" href="${ctx}/product/product_list" htmlTag="li"></paging:paging>

                    </ul>
                </div>

            </div>
        </div>

    </form>
</div>
<!------[end]内容区----->
</body>
</html>
